package com.hzdl.cinema.dao.impl;

import com.hzdl.cinema.dao.PlayDao;
import com.hzdl.cinema.domain.Play;
import com.hzdl.cinema.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class PlayDaoImpl implements PlayDao {

    JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());

	 @Override
    public Play findMyPlay(Integer playId) {
        String sql="select * from play where play_Id=?";
        Play play = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Play.class), playId);
        return play;
    }

    @Override
    public void modifyPlayName(Integer scheduleId, String playName) {
        String sql="update play set play_Name=? where play_Id in(select play_Id from schedule where schedule_Id = ?)";
        jdbcTemplate.update(sql,playName,scheduleId);
    }

    @Override
    public int findIdByName(String playName) {
        String sql="select play_Id from play where play_Name=?";
        int playId=0;
        try {
            playId = jdbcTemplate.queryForObject(sql, Integer.class,playName);
        }catch (Exception e){
//            e.printStackTrace();
        }
        return playId;
    }
}
